// 路由权限处理
import router from '@/router/index'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css'
import { RouteLocationNormalized } from 'vue-router'
NProgress.configure({ showSpinner: false })
router.beforeEach(async (to, from) => {
  NProgress.start()
  //
  if (to.path.indexOf('40') > -1) {
    to.meta = from.meta
    to.name = from.name
  }
  await handleRouterQuery(to, from)
})
router.afterEach(() => {
  NProgress.done()
  // 路由完成后做些事情
})

let currentPath: string

const Reg = /(^\/user(?!\/dashboard).*)/

// 处理路由上的公共参数 避免手动代入
async function handleRouterQuery(to: RouteLocationNormalized, from: RouteLocationNormalized) {
  const { path, fullPath } = to
  if (!Reg.test(path)) return
  if (currentPath !== fullPath) {
    currentPath = fullPath
  }
  return
}
